package com.tcenter.dao.entities;


import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 *
 */
@Entity
@Table(name = "group", catalog = "tcenterdb", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Group implements java.io.Serializable {

    private Integer id;
    private Course course;
    private Lecturer headOfGroup;
    private String name;
    private Set<Student> students = new HashSet<Student>(0);

    
    public Group() {
    }

    public Group(String name) {
        this.name = name;
    }

    public Group(String name, Course course, Lecturer headOfGroup) {
        this.course = course;
        this.headOfGroup = headOfGroup;
        this.name = name;
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "course_id")
    public Course getCourse() {
        return this.course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "head_id")
    public Lecturer getLecturer() {
        return this.headOfGroup;
    }

    public void setLecturer(Lecturer headOfGroup) {
        this.headOfGroup = headOfGroup;
    }

    @Column(name = "name", unique = true, nullable = false, length = 16)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "group")
    public Set<Student> getStudents() {
        return this.students;
    }

    public void setStudents(Set<Student> students) {
        this.students = students;
    }

}
